#-*- coding: UTF-8 -*-
__author__ = 'Administrator'
import datetime,urllib2,argparse

def timer(func):
    def wrapper(u):
        s = datetime.datetime.now()
        func(u)
        e = datetime.datetime.now()
        print (e-s).total_seconds()
    return wrapper

def getSpeed(url,n=1):
    for i in range(n):
        req(url)

@timer
def req(u):
    try:
        urllib2.urlopen(u)
    except:
        pass


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('url',type=str)
    parser.add_argument('-n',type=int,default=1)
    args = parser.parse_args()
    url = args.url
    n = args.n
    getSpeed(url,n)
